package com.bicycle.rentalsystem.dao.impl.admin;

import com.bicycle.rentalsystem.dao.admin.AdminDao;
import com.bicycle.rentalsystem.pojo.admin.Administrators;


import java.util.List;

/**
 * @author Third uncle
 * @date 2022/11/22 - 14:29
 */
public class AdminDaoImpl extends BaseDao implements AdminDao {
    @Override
    public Administrators getAdministratorsByid(Integer id) {
        String sql="select `id`,`administrator name`administratorName,`password`,`sex` from administrator where id=?";
        return queryForOne(Administrators.class,sql,id);
    }

    @Override
    public List<Administrators> getAdministrators() {
        String sql="select `id`,`administrator name`administratorName,`password`,`sex` from administrator";
        return queryForList(Administrators.class,sql);
    }

    @Override
    public void deleteAdminById(Integer id) {
        String sql="delete from administrator where id=?";
        update(sql,id);
    }

    @Override
    public void updateAdmin(Administrators admin) {
        String sql="update administrator set `administrator name`=?,`password`=?,`sex`=? where id=?";
        update(sql,admin.getAdministratorName(),admin.getPassword(),admin.getSex(),admin.getId()    );
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql="SELECT COUNT(*) FROM administrator ";
        Object o =  queryForSingleValue(sql);
        int i = Integer.parseInt(o.toString());
        return i;
    }

    @Override
    public List<Administrators> queryForPageItems(Integer begin, Integer pageSize) {
        String sql="select `id`,`administrator name`administratorName,`password`,`sex` from administrator limit ?,?";
        List<Administrators> list = queryForList(Administrators.class, sql, begin, pageSize);
        return list;
    }
}
